package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@RequestMapping("login")
@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @RequestMapping("login")
    public String login(HttpSession session, User user){
        if (user!=null && user.getUserName()!=null && user.getAddress()!=null){
            User user1=userService.login(user);
            if (user1!=null){
                session.setAttribute("user",user1);
                return "redirect:/user/findAll";
            }else {
                return "login";
            }
        }
        return "login";
    }
}
